<template>
	<!-- 预核保工作列表-预核保列表页面 -->
	<div class="fillcontain">
		<el-form :model="searchParams" ref="ruleForm" label-width="100px" class="search_container">
			<el-row>
				<el-col :span="6">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input v-model="searchParams.chdrnum" placeholder="保单号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="受理号" prop="caseno">
						<el-input v-model="searchParams.caseno" placeholder="受理号" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="质检状态" prop="routeid">
						<el-select v-model="searchParams.routeid" placeholder="质检状态" clearable>
							<el-option v-for="item in qualityTypes" :key="item.value" :label="item.name" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="8" class="text_right" style="float: right;">
					<el-button type="primary" icon="el-icon-search" @click="search"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
			</el-row>
		</el-form>
		<div class="contain">
			<div class="table_container">
				<el-table v-loading="loading" :data="tableData" highlight-current-row header-cell-class-name="table-header-class"
				 style="width:100%">
					<el-table-column min-width="100" property="orgName" label="机构" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="caseno" label="受理号" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="chdrnum" label="保单号" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" property="apptime" label="受理日" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="150" property="policyholdername" label="投保人姓名" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="150" property="insuredname" label="被保人姓名" align='center' show-overflow-tooltip>
					</el-table-column>
					<el-table-column min-width="100" label="质检状态" align='center' show-overflow-tooltip>
						<template slot-scope="scope">
						    <el-select v-model="scope.row.routeid" id="qualityType" @focus="getOldValue(scope.row.routeid)" @change="changeQualityType(scope.row)" >
						        <el-option
						        v-for="item in qualityTypes"
						        :key="item.value"
						        :label="item.name"
						        :value="item.value">
						        </el-option>
						    </el-select>
						</template>
					</el-table-column>
					<el-table-column min-width="120" label="批注" align='center' show-overflow-tooltip>
						<template slot-scope="scope">
							<el-link class ="point"  type="primary" @click="showComments(scope.row.taskno,scope.row.routeid)" :disabled="!interceptVip(scope.row, scope.index)">批注</el-link>
						</template>
					</el-table-column>
					<el-table-column
					min-width="80"
					   label="修改记录"
					   align='center'
					   show-overflow-tooltip>
					   <template slot-scope="scope">
					        <el-button type="text" size="small" @click="showChange(scope.row.taskno)" :disabled="!interceptVip(scope.row, scope.index)">修改记录</el-button>
					    </template>
					</el-table-column>
					<el-table-column  property="taskno" v-if="false"></el-table-column>
					<el-table-column  property="routeid" v-if="false"></el-table-column>
				</el-table>
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes" :page-size="paginations.pageSize"
							 :layout="paginations.layout" :total="paginations.total" :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
							 @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
			</div>
		</div>
		<!-- 流转/修改记录 -->
		<task-change-list  :business="'QUALITY'" :taskNo="changeTaskNo" :drawer="showChangeFlag" @close="hideChange"></task-change-list>
		<!-- 批注 -->
		<comments-list :taskNo="commentsTaskNo" :routeid="commentsRouteid" :drawer="showCommentsFlag" @close="hideComments"></comments-list>

	</div>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	// import { getComCheckList } from "@/api/comInquiry";
	import constant from '@/utils/constant';
	import {getSsyOrgMap} from "@/api/taskCenter/taskCommon";
	import TaskConstants, {
		call
	} from "@/api/taskManager/common"
	import commentsList from './commentsList'
	import taskChangeList from "../../taskCenter/taskChangeList";
	export default {
		components: {
			commentsList,
			taskChangeList
		},
		data() {
			return {
				oldValue:"",
				ssyMap: {},//机构对象
				changeTaskNo: "",
				commentsTaskNo: "",
				commentsRouteid: "",
				showCommentsFlag: false,
				showChangeFlag: false,
				searchParams: {
					routeid:'',
					caseno: '',
					chdrnum: '',
					pageNumber: '',
					pageSize: ''
				},
				qualityTypes:TaskConstants.qualityTypes,
				emptySearchParams: {},
				tableData: [],
				loading: false,
				//需要给分页组件传的信息
				paginations: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 10, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
				},
			}
		},
		activated(){
		    document.onkeydown = (event)=>{
		        var e = event || window.event || arguments.callee.caller.arguments[0];
		        if (e && e.keyCode == 113) {
		            this.search()();
		        }
		    };
		},
		created() {
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
		},
		mounted() {
			getSsyOrgMap().then(data => this.ssyMap = data);
		},
		methods: {
			showChange(taskNo) {
				this.changeTaskNo = taskNo;
				this.showChangeFlag = true;
			},
			hideChange() {
				this.changeTaskNo = "";
				this.showChangeFlag = false;
			},
			showComments(taskNo,routeid) {
				this.commentsTaskNo = taskNo;
				this.commentsRouteid = routeid;
				this.showCommentsFlag = true;
			},
			hideComments() {
				this.commentsTaskNo = "";
				this.commentsRouteid = "";
				this.showCommentsFlag = false;
			},
			getOrgName(value) {
			    if (this.ssyMap && this.ssyMap[value] && this.ssyMap[value].sorgname)
			        return this.ssyMap[value].sorgname;
			    else
			        return value;
			},
			getOldValue(routeid) {
				this.oldValue = routeid
			},
			//修改状态
			changeQualityType(row) {
				if (this.oldValue == 'quality_pass') {
					this.$message.error("质检已通过，无法更改状态！")
					return
				}
				let param ={
					'taskno':row.taskno,
					'routeid':row.routeid,
					'caseno': row.caseno,
					'chdrnum':row.chdrnum
				}
				this.$store.dispatch('loading/CHANGE_LOADING', true)
				let type = document.getElementById("qualityType");
				call(TaskConstants.apis.qualityRouteidChange,param,"post").then( res =>{
					if(res.resultCode == constant.SUCCESS) {
						this.$message.success("修改成功！");
					} else {
						row.routeid = this.oldValue
					}
					this.$store.dispatch('loading/CHANGE_LOADING', false)
				}).catch(err =>{
					this.$store.dispatch('loading/CHANGE_LOADING', false)
					row.routeid = this.oldValue
				})
			},
			// 综合查询列表
			getList() {
				this.paginations.total = 0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				this.$store.dispatch('loading/CHANGE_LOADING', true)
				call(TaskConstants.apis.qualityList,this.searchParams,"post").then(res =>{
					if (res.resultCode == constant.SUCCESS && res.data && res.data.list.length) {
						this.tableData = res.data.list
						this.paginations.total = pageData.total;
						this.paginations.currentPage = pageData.pageNum;
						this.tableData.forEach( item =>{
							item['orgName'] = this.getOrgName(item.organ)
						})
					} else {
						this.$message.error("无符合条件任务！");
					}
					this.$store.dispatch('loading/CHANGE_LOADING', false)
				}).catch( err =>{
					this.$store.dispatch('loading/CHANGE_LOADING', false)
				})
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageSize = pageSize;
				this.getList();
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.getList();
			},
			// 根据条件查询列表
			search() {
				this.paginations.pageIndex = 1;
				this.getList();
			},
			// 清除查询条件
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
      // vip权限拦截
      interceptVip(row, index) {
        let rowStr = JSON.stringify(row);
        if (rowStr.indexOf("*") > -1) {
          return false;
        }
        return true;
      },

		}
	}
</script>

<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;
	}

	.contain {
		background: #fff;
		padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}

	.operationIcon {
		// padding: 12px;
		border: 1px solid #e5e5e5;
		border-radius: 50%;
		width: 22px;
		height: 22px;
		display: inline-block;
		cursor: pointer;
		box-shadow: 0 0 3px #f9f9f9;

		.svg-icon {
			font-size: 14px;
			fill: #68a3fc;
		}
	}

	.search_container {
		padding: 20px 20px 0 20px;
		border-top: 1px solid #e1e1e1;
	}
</style>
